package org.jeecg.common.base;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import org.springframework.beans.BeanUtils;


/**
 * @author yann
 * @date 2020/3/4
 * @description:
 */
public class BaseServiceImpl<M extends MyBaseMapper<T>,T> extends ServiceImpl<M, T> implements IBaseService<T> {

    /**
     * 填充字段删除方法
     * @param entity
     * @return
     */
    @Override
    public boolean removeByIdWithFill(T entity) {
        return SqlHelper.retBool(this.baseMapper.deleteByIdWithFill(entity));
    }

    @Override
    public <S> S copy(Object source, Class<S> clazz){
        try {
            S s = clazz.newInstance();
            BeanUtils.copyProperties(source,s);
            return s;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }


}
